package com.lei.tets;


import com.lei.domain.Order;
import com.lei.domain.Role;
import com.lei.domain.User;
import com.lei.mapper.OrderMapper;
import com.lei.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @ClassName Test
 * @Description TODO
 * @Author Admin
 * @Date 2021/10/29 15:52
 * @Version 1.0
 */
public class Test {
@org.junit.jupiter.api.Test
    public void test() throws IOException {
    InputStream resourceAsStream = Resources.getResourceAsStream("SqlMappConfig.xml");
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
    SqlSession sqlSession = sessionFactory.openSession();
    OrderMapper mapper = sqlSession.getMapper(OrderMapper.class);
    List<Order> list = mapper.findAll();
    System.out.println(list);
    for (Order order : list) {
        System.out.println(order);
    }
    System.out.println();
    UserMapper mapper1 = sqlSession.getMapper(UserMapper.class);
    List<User> userList = mapper1.findAll();
    for (User user : userList) {
        System.out.println(user);
    }

    sqlSession.close();


}
@org.junit.jupiter.api.Test
    public void test2() throws IOException {
    InputStream resourceAsStream = Resources.getResourceAsStream("SqlMappConfig.xml");
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
    SqlSession sqlSession = sessionFactory.openSession();
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    List<User> userList=mapper.findUserAndRoleAll();
    for (User user : userList) {
        System.out.println(user);
    }


}

}
